<?php
namespace application\cms\controller\admin;

class index{

    // cms后台管理 cms/admin/index
    function index(){   
        // 统计
        $tongji = [];

        $sql="select count(*) from ".tablename('rj_cms_article')." ";
        $ret= $GLOBALS['db']->query($sql)->fetch();
        $tongji['article']['zong'] = $ret[0];
        $sql="select count(*) from ".tablename('rj_cms_article')." where status=1 ";
        $ret= $GLOBALS['db']->query($sql)->fetch();
        $tongji['article']['fabu'] = $ret[0];

        $sql="select count(*) from ".tablename('rj_cms_goods')." ";
        $ret= $GLOBALS['db']->query($sql)->fetch();
        $tongji['goods']['zong'] = $ret[0];
        $sql="select count(*) from ".tablename('rj_cms_goods')." where status=1 ";
        $ret= $GLOBALS['db']->query($sql)->fetch();
        $tongji['goods']['fabu'] = $ret[0];

        // chart
        // 分类文章统计
        $sql="SELECT a_s.sort_name as name,count(a.id) as value FROM ".tablename('rj_cms_article_sort')." a_s "
                    . " LEFT JOIN ".tablename('rj_cms_article')." a " 
                    . " ON a_s.sort_id=a.sort_id GROUP BY a_s.sort_id,a_s.sort_name";
        $rs_chart_article=pdo_fetchall($sql);
        // 分类商品统计
        $sql="SELECT g_s.sort_name as name,count(g.id) as value FROM ".tablename('rj_cms_goods_sort')." g_s " 
                    . " LEFT JOIN ".tablename('rj_cms_goods')." g " 
                    . " ON g_s.sort_id=g.sort_id GROUP BY g_s.sort_id,g_s.sort_name";
        $rs_chart_goods=pdo_fetchall($sql);
		
        // 每日浏览量
        $sql="select hit_day,count(*) AS c from ".tablename('rj_cms_hit_log')." GROUP BY hit_day  order by hit_day desc limit 0,30 ";
        $rs_chart_hit= $GLOBALS['db']->query($sql)->fetchall();
        krsort($rs_chart_hit);
        $date_str="[";
        $count_str="[";
        //print_r($rs);
        foreach($rs_chart_hit as $k=>$row){
            $date_str.="'". $row['hit_day'] ."'";
            $count_str.=$row['c'];
            if($k>0){
                $date_str.=",";
                $count_str.=",";
            }
        }
        $date_str .= "]";
        $count_str.= "]";

        require view('admin/index/index.tpl.php');
    } 


}